package com.dev.op.controller;

import com.dev.op.VO.TestVO;
import com.dev.op.entity.Problem;
import com.dev.op.entity.TestCase;
import com.dev.op.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/test")
@PreAuthorize("hasAnyRole('admin')")
public class TestController {

    @Autowired
    RedisService redisService;

    @PostMapping("/problem")
    public boolean testRedisSaveProblem(@RequestBody Problem problem) {
        System.out.println(problem);
        return redisService.saveProblem(problem,36000);
    }

    @GetMapping("/problem/{problemId}")
    public Problem getProblem(@PathVariable("problemId") String problemId) {
        return redisService.getProblem(problemId);
    }

    @DeleteMapping("/problem/{problemId}")
    public boolean deleteProblem(@PathVariable("problemId") String problemId) {
        return redisService.deleteProblem(problemId);
    }

    @PostMapping("/testCase")
    public boolean saveTestCases(@RequestBody TestVO testVO) {
        List<TestCase> testCases = testVO.getTestCases();
        return redisService.saveTestCases(testCases,36000);
    }

    @GetMapping("/testCase/{problemId}")
    public List<TestCase> getTestCases(@PathVariable("problemId") String problemId) {
        return redisService.getTestCase(problemId);
    }

    @DeleteMapping("/testCase/{problemId}")
    public boolean deleteTestCase(@PathVariable("problemId") String problemId) {
        return redisService.deleteTestCase(problemId);
    }
}
